home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / kernel / fsutil / fsutilSubr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-12-19  |  6.7 KB  |  311 lines

  1. /* 
  2.  * fsutilSubr.c --
  3.  *
  4.  *    Miscellaneous routines.
  5.  *
  6.  * Copyright 1986 Regents of the University of California
  7.  * All rights reserved.
  8.  */
  9.  
  10. #ifndef lint
  11. static char rcsid[] = "$Header: /cdrom/src/kernel/Cvsroot/kernel/fsutil/fsutilSubr.c,v 9.3 91/09/10 18:24:14 rab Exp $ SPRITE (Berkeley)";
  12. #endif not lint
  13.  
  14.  
  15. #include <sprite.h>
  16.  
  17. #include <fs.h>
  18. #include <vm.h>
  19. #include <rpc.h>
  20. #include <fsutil.h>
  21. #include <fsdm.h>
  22. #include <fslcl.h>
  23. #include <fsprefix.h>
  24. #include <fsNameOps.h>
  25. #include <fspdev.h>
  26. #include <fsStat.h>
  27. #include <devDiskLabel.h>
  28. #include <dev.h>
  29. #include <sync.h>
  30. #include <timer.h>
  31. #include <proc.h>
  32. #include <hash.h>
  33. #include <fsrmt.h>
  34.  
  35. #include <stdio.h>
  36.  
  37.  
  38.  
  39. /*
  40.  *----------------------------------------------------------------------
  41.  *
  42.  * Fsutil_DomainInfo --
  43.  *
  44.  *    Return info about the given domain.
  45.  *    FIX ME FIX ME FIX ME
  46.  *    This should be replaced by a call through the domain switch.
  47.  *    The prefix table module has the domain type, so can do this.
  48.  *    For now, we infer the domain type from the stream type.
  49.  *
  50.  * Results:
  51.  *    A return status.
  52.  *
  53.  * Side effects:
  54.  *    None.
  55.  *
  56.  *----------------------------------------------------------------------
  57.  */
  58. ReturnStatus 
  59. Fsutil_DomainInfo(fileIDPtr, domainInfoPtr)
  60.     Fs_FileID        *fileIDPtr;    /* FileID from the prefix table,
  61.                      * This can be changed to make
  62.                      * it match with what a user sees
  63.                      * when it stats the file.  This
  64.                      * is important when computing
  65.                      * the current directory in getwd(). */
  66.     Fs_DomainInfo    *domainInfoPtr;    /* Fill in with # free blocks, etc */
  67. {
  68.     ReturnStatus    status;
  69.  
  70.     switch (fileIDPtr->type) {
  71.     case FSIO_LCL_FILE_STREAM:
  72.         status = Fsdm_DomainInfo(fileIDPtr, domainInfoPtr);
  73.         break;
  74.     case FSIO_PFS_NAMING_STREAM:
  75.     case FSIO_RMT_FILE_STREAM:
  76.         status = Fsrmt_DomainInfo(fileIDPtr, domainInfoPtr);
  77.         break;
  78.     case FSIO_LCL_PSEUDO_STREAM:
  79.         status = FspdevPfsDomainInfo(fileIDPtr, domainInfoPtr);
  80.         break;
  81.     default:
  82.         printf("Fsutil_DomainInfo: Unexpected stream type <%d>\n",
  83.             fileIDPtr->type);
  84.         status = FS_DOMAIN_UNAVAILABLE;
  85.         break;
  86.     }
  87.     if (status != SUCCESS) {
  88.     domainInfoPtr->maxKbytes = -1;
  89.     domainInfoPtr->freeKbytes = -1;
  90.     domainInfoPtr->maxFileDesc = -1;
  91.     domainInfoPtr->freeFileDesc = -1;
  92.     domainInfoPtr->blockSize = -1;
  93.     }
  94.  
  95.     return(status);
  96. }
  97.  
  98. /*
  99.  *----------------------------------------------------------------------
  100.  *
  101.  * Fsutil_FileError --
  102.  *
  103.  *    Print an error message about a file.
  104.  *
  105.  * Results:
  106.  *    None.
  107.  *
  108.  * Side effects:
  109.  *    None.
  110.  *
  111.  *----------------------------------------------------------------------
  112.  */
  113. void
  114. Fsutil_FileError(hdrPtr, string, status)
  115.     Fs_HandleHeader *hdrPtr;
  116.     char *string;
  117.     int status;
  118. {
  119.     if (hdrPtr == (Fs_HandleHeader *)NIL) {
  120.     printf("(NIL handle) %s: ", string);
  121.     } else {
  122.     Net_HostPrint(hdrPtr->fileID.serverID,
  123.               Fsutil_FileTypeToString(hdrPtr->fileID.type));
  124.     printf(" \"%s\" <%d,%d> %s: ", Fsutil_HandleName(hdrPtr),
  125.         hdrPtr->fileID.major, hdrPtr->fileID.minor, string);
  126.     }
  127.     Fsutil_PrintStatus(status);
  128.     printf("\n");
  129. }
  130.  
  131. /*
  132.  *----------------------------------------------------------------------
  133.  *
  134.  * Fsutil_PrintStatus --
  135.  *
  136.  *    Print out an error status, using a mnemonic if possible.
  137.  *
  138.  * Results:
  139.  *    None.
  140.  *
  141.  * Side effects:
  142.  *    A print statement.
  143.  *
  144.  *----------------------------------------------------------------------
  145.  */
  146. void
  147. Fsutil_PrintStatus(status)
  148.     int status;
  149. {
  150.     switch (status) {
  151.     case SUCCESS:
  152.         break;
  153.     case FS_DOMAIN_UNAVAILABLE:
  154.         printf("domain unavailable");
  155.         break;
  156.     case FS_VERSION_MISMATCH:
  157.         printf("version mismatch");
  158.         break;
  159.     case FAILURE:
  160.         printf("cacheable/busy conflict");
  161.         break;
  162.     case RPC_TIMEOUT:
  163.         printf("rpc timeout");
  164.         break;
  165.     case RPC_SERVICE_DISABLED:
  166.         printf("server rebooting");
  167.         break;
  168.     case FS_STALE_HANDLE:
  169.         printf("stale handle");
  170.         break;
  171.     case DEV_RETRY_ERROR:
  172.     case DEV_HARD_ERROR:
  173.         printf("DISK ERROR");
  174.         break;
  175.     case FS_NO_DISK_SPACE:
  176.         printf("out of disk space");
  177.     default:
  178.         printf("<%x>", status);
  179.         break;
  180.     }
  181. }
  182.  
  183. /*
  184.  *----------------------------------------------------------------------
  185.  *
  186.  * Fsutil_FileTypeToString --
  187.  *
  188.  *    Map a stream type to a string.  Used for error messages.
  189.  *
  190.  * Results:
  191.  *    A string.
  192.  *
  193.  * Side effects:
  194.  *    None.
  195.  *
  196.  *----------------------------------------------------------------------
  197.  */
  198. char *
  199. Fsutil_FileTypeToString(type)
  200.     int type;
  201. {
  202.     register char *fileType;
  203.  
  204.     switch (type) {
  205.     case FSIO_STREAM:
  206.         fileType = "Stream";
  207.         break;
  208.     case FSIO_LCL_FILE_STREAM:
  209.         fileType = "File";
  210.         break;
  211.     case FSIO_RMT_FILE_STREAM:
  212.         fileType = "RmtFile";
  213.         break;
  214.     case FSIO_LCL_DEVICE_STREAM:
  215.         fileType = "Device";
  216.         break;
  217.     case FSIO_RMT_DEVICE_STREAM:
  218.         fileType = "RmtDevice";
  219.         break;
  220.     case FSIO_LCL_PIPE_STREAM:
  221.         fileType = "Pipe";
  222.         break;
  223.     case FSIO_RMT_PIPE_STREAM:
  224.         fileType = "RmtPipe";
  225.         break;
  226. #ifdef notdef
  227.     case FS_LCL_NAMED_PIPE_STREAM:
  228.         fileType = "NamedPipe";
  229.         break;
  230.     case FS_RMT_NAMED_PIPE_STREAM:
  231.         fileType = "RmtNamedPipe";
  232.         break;
  233. #endif
  234.     case FSIO_CONTROL_STREAM:
  235.         fileType = "PdevControlStream";
  236.         break;
  237.     case FSIO_SERVER_STREAM:
  238.         fileType = "SrvStream";
  239.         break;
  240.     case FSIO_LCL_PSEUDO_STREAM:
  241.         fileType = "LclPdev";
  242.         break;
  243.     case FSIO_RMT_PSEUDO_STREAM:
  244.         fileType = "RmtPdev";
  245.         break;
  246.     case FSIO_PFS_CONTROL_STREAM:
  247.         fileType = "PfsControlStream";
  248.         break;
  249.     case FSIO_PFS_NAMING_STREAM:
  250.         fileType = "PfsNamingStream";
  251.         break;
  252.     case FSIO_LCL_PFS_STREAM:
  253.         fileType = "LclPfs";
  254.         break;
  255.     case FSIO_RMT_PFS_STREAM:
  256.         fileType = "RmtPfs";
  257.         break;
  258. #ifdef INET
  259.     case FSIO_RAW_IP_STREAM:
  260.         fileType = "RawIp Socket";
  261.         break;
  262.     case FSIO_UDP_STREAM:
  263.         fileType = "UDP Socket";
  264.         break;
  265.     case FSIO_TCP_STREAM:
  266.         fileType = "TCP Socket";
  267.         break;
  268. #endif
  269. #ifdef notdef
  270.     case FS_RMT_UNIX_STREAM:
  271.         fileType = "UnixFile";
  272.         break;
  273.     case FS_RMT_NFS_STREAM:
  274.         fileType = "NFSFile";
  275.         break;
  276. #endif
  277.     default:
  278.         fileType = "<unknown file type>";
  279.         break;
  280.     }
  281.     return(fileType);
  282. }
  283.  
  284. /*
  285.  *----------------------------------------------------------------------
  286.  *
  287.  * Fsutil_GetFileName --
  288.  *
  289.  *    Return a pointer to the file name for the given stream.
  290.  *
  291.  * Results:
  292.  *    Pointer to file name from handle of given stream.
  293.  *
  294.  * Side effects:
  295.  *    None.
  296.  *
  297.  *----------------------------------------------------------------------
  298.  */
  299. char *
  300. Fsutil_GetFileName(streamPtr)
  301.     Fs_Stream    *streamPtr;
  302. {
  303.     if (streamPtr->hdr.name != (char *)NIL) {
  304.     return(streamPtr->hdr.name);
  305.     } else if (streamPtr->ioHandlePtr != (Fs_HandleHeader *)NIL) {
  306.     return(streamPtr->ioHandlePtr->name);
  307.     } else {
  308.     return("(noname)");
  309.     }
  310. }
  311.